package com.zzyl.nursing.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.core.domain.R;
import com.zzyl.common.core.page.TableDataInfo;
import com.zzyl.nursing.domain.NursingTask;
import com.zzyl.nursing.dto.NursingTaskCancelDto;
import com.zzyl.nursing.dto.NursingTaskExecuteDto;
import com.zzyl.nursing.dto.NursingTaskExecuteResultDto;

import com.zzyl.nursing.service.INursingTaskService;
import com.zzyl.nursing.vo.NursingTaskDetailVo;
import com.zzyl.nursing.vo.NursingTaskVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 护理任务Controller
 * 
 * @author ruoyi
 * @date 2025-08-04
 */
@RestController
@RequestMapping("/nursing/task")
@Api(tags = "护理任务相关接口")
public class NursingTaskController extends BaseController
{
    @Autowired
    private INursingTaskService nursingTaskService;
    /**
     * 查询护理任务列表
     */
    @GetMapping("/list")
    @ApiOperation(value = "获取护理任务列表")
    public TableDataInfo<List<NursingTaskVo>> list(NursingTask nursingTask,
                                                   @RequestParam(value = "nurseId", required = false) Long nurseId,
                                                   @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                                   @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                                   @RequestParam(value = "startTime", required = false) String startTime,
                                                   @RequestParam(value = "endTime", required = false) String endTime)
    {
        // 如果传入了nurseId参数，设置到nursingTask对象中
        if (nurseId != null) {
            nursingTask.setNursingId(nurseId.toString());
        }

        // 执行分页查询
        IPage<NursingTaskVo> page = nursingTaskService.selectNursingTaskList(nursingTask, pageNum, pageSize);

        // 返回分页结果
        TableDataInfo<List<NursingTaskVo>> dataTable = getDataTable(page.getRecords());
        dataTable.setTotal(page.getTotal());
        return dataTable;
    }
    /**
     * 获取护理任务详细信息
     */
    @GetMapping(value = "/{id}")
    @ApiOperation("获取护理任务详细信息")
    public R<NursingTaskDetailVo> getInfo(@ApiParam(value = "护理任务ID", required = true) @PathVariable("id") Integer id)
    {
        return R.ok(nursingTaskService.selectNursingTaskById(id));
    }

/**
 * 取消任务
 */
@PutMapping (value = "/cancel")
@ApiOperation("取消任务")
public AjaxResult cancelTask(@RequestBody  NursingTaskCancelDto nursingTaskCancelDto){
    nursingTaskService.cacelTask(nursingTaskCancelDto);
    return success();
}

/**
 * 任务执行
 */
@PutMapping (value = "/do")
@ApiOperation("任务执行")
public AjaxResult executeTask(@RequestBody NursingTaskExecuteDto nursingTaskExecuteDto){
    nursingTaskService.executeTask(nursingTaskExecuteDto);
    return success();
}
/**
 * 任务改期
 */
@PutMapping (value = "/updateTime")
@ApiOperation("任务改期")
public AjaxResult updateTask(@RequestBody  NursingTaskExecuteResultDto nursingTaskExecuteDto){
    nursingTaskService.updateTask(nursingTaskExecuteDto);
    return success();
}

}
